package com.db.patterns.singleton.demo07;

import com.db.patterns.singleton.demo05.Singleton;
import lombok.extern.slf4j.Slf4j;

import java.io.*;

@Slf4j
public class Client {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        writeObjectToFile();
        readObjectFromFile();
        readObjectFromFile();
    }

    public static void writeObjectToFile() throws IOException {
        Singleton instance = Singleton.getInstance();
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("instance.txt"));
        oos.writeObject(instance);
        oos.close();
    }

    public static void readObjectFromFile() throws IOException, ClassNotFoundException {
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("instance.txt"));
        Singleton singleton1 = (Singleton) ois.readObject();
        log.info(singleton1.toString());
        ois.close();
    }
}
